//
//  StatusCellBottomView.swift
//  SinaWeibo
//
//  Created by Tony-ztb on 15/12/19.
//  Copyright © 2015年 Tony-ztb. All rights reserved.
//

import UIKit
import SnapKit

class StatusCellBottomView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: 点击事件
    @objc private func commentBtnDidClick() {
        print(__FUNCTION__)
        // 跳转到的评论视图的控制器
        let tempVC = TempViewController()
        
//        let nav = UINavigationController(rootViewController: tempVC)
        // modal到评论 控制器
//        self.navController()?.presentViewController(nav, animated: true, completion: nil)
        // push到评论控制器
        self.navController()?.pushViewController(tempVC, animated: true)
    }
    
    
    private func setupUI() {
        
        addSubview(retweetBtn)
        addSubview(commentBtn)
        addSubview(likeBtn)
        
        // 设置子视图的约束
        retweetBtn.snp_makeConstraints { (make) -> Void in
            make.top.left.bottom.equalTo(self)
        }
        
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetBtn.snp_right)
            make.top.bottom.equalTo(self)
            make.width.equalTo(retweetBtn.snp_width)
        }
        
        likeBtn.snp_makeConstraints { (make) -> Void in
//            make.right.equalTo(self.snp_right)
            make.left.equalTo(commentBtn.snp_right)
            make.top.bottom.right.equalTo(self)
            make.width.equalTo(commentBtn.snp_width)
        }
        
        // MARK: 评论按钮commentBtn的点击事件
        commentBtn.addTarget(self, action: "commentBtnDidClick", forControlEvents: .TouchUpInside)
        
        
        
        // 两条分割线
        let sepView1 = sepView()
        let sepView2 = sepView()
        
        let w: CGFloat = 0.5
        let scale = 0.4
        
        addSubview(sepView1)
        addSubview(sepView2)
        
        sepView1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetBtn.snp_right)
            make.width.equalTo(w)
            make.height.equalTo(self.snp_height).multipliedBy(scale)
            make.centerY.equalTo(self.snp_centerY)
        }
        
        
        sepView2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentBtn.snp_right)
            make.width.equalTo(w)
            make.height.equalTo(self.snp_height).multipliedBy(scale)
            make.centerY.equalTo(self.snp_centerY)
        }
        
    }
    
    // 生成分割线视图
    private func sepView() -> UIView{
        let v = UIView()
        v.backgroundColor = UIColor.darkGrayColor()
        return v
    }

    // 懒加载子视图
    private lazy var retweetBtn: UIButton = UIButton(backImageName: nil, title: "转发", fontSize: 10, color: UIColor.darkGrayColor(), imageName: "timeline_icon_retweet")
    private lazy var commentBtn: UIButton = UIButton(backImageName: nil, title: "评论", fontSize: 10, color: UIColor.darkGrayColor(), imageName: "timeline_icon_comment")
    private lazy var likeBtn: UIButton = UIButton(backImageName: nil, title: "赞", fontSize: 10, color: UIColor.darkGrayColor(), imageName: "timeline_icon_unlike")
}
